<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="12" >
            <a-form-item label="商品id" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-popup
                v-decorator="['goodsName', validatorRules.goodsName]"
                :trigger-change="true"
                org-fields="id,name,unit_name"
                dest-fields="goodsId,goodsName,unitName"
                code="goods_select"
                @callback="popupCallback"/>
            </a-form-item>
            <a-form-item label="goodsId"  style="height: 0px;overflow: hidden;margin-bottom: 0">
              <a-input v-decorator="['goodsId']" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12" >
            <a-form-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['title', validatorRules.title]" placeholder="请输入标题"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" v-if="isMiaosha">
              <j-date placeholder="请选择开始时间" v-decorator="['startTime', validatorRules.startTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:00:00" style="width: 100%"/>
            </a-form-item>
            <a-form-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" v-else>
              <j-date placeholder="请选择开始时间" v-decorator="['startTime', validatorRules.startTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="12" >
            <a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" v-if="isMiaosha">
              <j-date placeholder="请选择结束时间" v-decorator="['endTime', validatorRules.endTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:00:00" style="width: 100%"/>
            </a-form-item>
            <a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" v-else>
              <j-date placeholder="请选择结束时间" v-decorator="['endTime', validatorRules.endTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <!--<a-col :span="12" >
            <a-form-item label="商品状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="radio" disabled v-decorator="['status', validatorRules.status]" :trigger-change="true" dictCode="goods_status" placeholder="请选择商品状态[-1：已删除0:已下架,1:已上架]"/>
            </a-form-item>
          </a-col>-->
          <a-col :span="12" >
            <a-form-item label="新品状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="radioButton" v-decorator="['newStatus', validatorRules.newStatus]" :trigger-change="true" dictCode="new_status" placeholder="请选择新品状态[0:非新品,1:新品]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12" >
            <a-form-item label="推荐状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="radioButton" v-decorator="['recommandStatus', validatorRules.recommandStatus]" :trigger-change="true" dictCode="recommand_status" placeholder="请选择推荐状态"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="售卖类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="radioButton" v-decorator="['saleType', validatorRules.sale_type]" :trigger-change="true" dictCode="sale_type" placeholder="请选择售卖类型" @change="saleChange"/>
            </a-form-item>
          </a-col>
          <a-col  :span="12">
            <a-form-item label="初始售卖" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['initSale', validatorRules.initSale]" placeholder="请输入初始售卖" :min="0" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="12" >
            <a-form-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['sort', validatorRules.sort]" placeholder="请输入排序" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="12" >
            <a-form-item label="佣金" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['commission', validatorRules.commission]" :min="0" placeholder="请输入佣金" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="12" >
            <a-form-item label="积分" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['integral', validatorRules.integral]" placeholder="请输入积分" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="12" >
            <a-form-item label="限购" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['limitSale', validatorRules.limitSale]" :min="0" placeholder="请输入限购数量" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="12" >
            <a-form-item label="关键字" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['keywords', validatorRules.keywords]" placeholder="请输入关键字" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24" >
            <a-form-item label="分享图片" :labelCol="{span:3}" :wrapperCol="{span:21}" extra="水平:垂直 = 5:4">
              <j-image-upload :isMultiple="formDisabled" v-decorator="['sharePic', validatorRules.sharePic]"></j-image-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
      <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="上架商品明细" :key="refKeys[0]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[0]"
          :loading="goodsShelfDetailTable.loading"
          :columns="goodsShelfDetailTable.columns"
          :dataSource="goodsShelfDetailTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="false">

            <template v-slot:buttonBefore="props" v-if="!formDisabled">
              <a-button type="primary" icon="plus" @click="add1">新增</a-button>
              <a-button type="primary" icon="minus" @click="del1" style="margin-left: 10px;margin-bottom: 20px" >删除</a-button>

            </template>
<!--          <template v-slot:quantitySlot="props" >

            <a-input-number :value="props.value" :disabled="!numDisabled" @change="kkk(props,$event)"></a-input-number>

          </template>-->
            <template v-slot:fileSlot="props">
<!--              <a-select  style="width: 100%" @change="xialaxuanze(props,$event)" :value="goodsShelfDetailTable.dataSource[props.index].goodsSpecsId"  :disabled="detailsDisabled">-->
              <a-select  style="width: 100%" :defaultValue="props.text" @change="xialaxuanze(props,$event)"   :disabled="formDisabled">
                <a-select-option :key="i.id" v-for="(i,index) in optionsArray">
                  <a-tag color="#108ee9" v-for="(m,index1) in i.specsValues">{{m.attributeName+':'+m.attributeValues}}</a-tag>
                </a-select-option>
              </a-select>
            </template>
          <template v-slot:unitNameSlot="props">
            <div style="color:#FFA765"   v-if="goodsShelfDetailTable.unitName==''||goodsShelfDetailTable.unitName==null||goodsShelfDetailTable.unitName==undefined" >未设置</div>
            <div   v-else  >{{goodsShelfDetailTable.unitName}}</div>
<!--              {{unitName==''||unitName==null||unitName==undefined?'未设置':unitName}}-->
          </template>
          </j-editable-table>
      </a-tab-pane>
    </a-tabs>

    <!--<a-modal
      title="商品规格选择"
      :visible="visible1"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <a-select  style="width: 100%" @change="xialaxuanze">
        <a-select-option :value="i.id" v-for="(i,index) in optionsArray">
          <a-tag color="#108ee9" v-for="(m,index1) in i.specsValues">{{m.attributeName+':'+m.attributeValues}}</a-tag>
        </a-select-option>
      </a-select>
    </a-modal>-->
  </a-spin>
</template>

<script>

  import pick from 'lodash.pick'
  import { getAction } from '@/api/manage'
  import { FormTypes,getRefPromise,VALIDATE_NO_PASSED ,validateFormAndTables} from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'
  import JDate from '@/components/jeecg/JDate'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import JImageUpload from '@/components/jeecg/JImageUpload'

  export default {
    name: 'GoodsShelfForm',
    mixins: [JEditableTableMixin],
    components: {
      JFormContainer,
      JDate,
      JDictSelectTag,
      JImageUpload
    },
    watch:{
      /*goodsShelfDetailTable:{
        handler(newVal) {
          console.log(newVal)

        },
        deep: true,
        immediate: false,
      },
      optionsArray:{
        handler(newVal) {
          console.log(newVal)
          this.goodsShelfDetailTable.columns[0].options = newVal
        },
        deep: true,
        immediate: false,
      }*/
    },
    data() {
      return {
        //修改数量状态
        isFixNum:false,
        /*新增时候自动创建序号*/
        addMaxSort:false,
        /*是否秒杀商品*/
        isMiaosha:false,
        detailsDisabled:false,
        commontELE:'',
        unitName:null,//库存单位
        visible1:false,
        confirmLoading:false,
        ModalText:'dasdadad',
        goodsIds:[],
        optionsArray:[],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
          sale_type:{
            initialValue:'0',
            rules: [
              { required: true, message: '请输入商品id!'},
            ]
          },
          goodsName: {
            rules: [
              { required: true, message: '请选择商品!'},
            ]
          },
          limitSale: {
            initialValue:'0',
            rules: [
              { required: true, message: '请输入限购数量!'},
            ]
          },
          goodsId: {
            rules: [
              { required: true, message: '请输入商品id!'},
            ]
          },
          title: {
            rules: [
              { required: true, message: '请输入标题!'},
            ]
          },
          startTime: {
            rules: [
              { required: true, message: '请输入开始时间!'},
            ]
          },
          endTime: {
            rules: [
              { required: true, message: '请输入结束时间!'},
            ]
          },
          status: {
            initialValue:'0',
            rules: [
              { required: true, message: '请输入商品状态!'},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
            ]
          },
          newStatus: {
            initialValue:'0',
            rules: [
              { required: true, message: '请输入新品状态!'},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
            ]
          },
          recommandStatus: {
            initialValue:'0',
            rules: [
              { required: true, message: '请输入推荐状态!'},
              { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
            ]
          },
          sort: {
            rules: [
              { required: true, message: '请输入排序!'},
              { pattern: /^[+]{0,1}(\d+)$/, message: '请输入正整数数字!'},
            ]
          },
          commission: {
            rules: [
              { required: true, message: '请输入佣金!'},
              // { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
            ]
          },
          sharePic: {
            rules: [
              { required: true, message: '请上传分享图!'},
              // { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
            ]
          },
          integral: {
            rules: [
              { required: false},
              { pattern: /^-?\d+$/, message: '请输入整数!'},
            ]
          },
        },
        refKeys: ['goodsShelfDetail', ],
        tableKeys:['goodsShelfDetail', ],
        activeKey: 'goodsShelfDetail',
        // 上架商品明细
        goodsShelfDetailTable: {
          loading: false,
          dataSource: [],
          unitName:null,
          columns: [
            /*{
              title: '商品规格ID',
              key: 'goodsSpecsId',
              type: FormTypes.input,
              disabled:true,
              width:"200px",
              options:[],
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },*/
            {
              title: '商品规格ID',
              key: 'goodsSpecsId',
              type:'hidden'
            },
            {
              title: '商品规格',
              key: 'specsStr',
              type: FormTypes.slot,
              slotName:'fileSlot',
              width:"300px",
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{
                handler(type, value, row, column, callback, target){
                  /*console.log(value)
                  if (!value){
                    callback(false,'请选择${title}!')
                  }else {
                    callback()
                  }*/
                  let { values } = target.getValuesSync({ validate:false})
                  let count = 0
                  console.log(values)
                  for (let resultElement of values) {
                    if (resultElement['goodsSpecsId']==''){
                      if (++count >= 1){
                        callback(false, '请选择${title}!')
                        return
                      }

                    }
                  }
                  callback()
                },
                message: '请选择${title}!'
              }],
            },
            {
              title: '上架数量',
              key: 'quantity',
              // slotName:'quantitySlot',
              type: FormTypes.inputNumber,
              width:"100px",
              placeholder: '请输入${title}',
              defaultValue: 0,
              // validateRules: [{ required: true, message: '${title}不能为空' }],
              validateRules: [{
                required: true,
                handler(type, value, row, column, callback, target){
                  console.log(value)

                  if (!(/(^[0-9]\d*$)/.test(value))){
                    callback(false, '${title}数量必须是正整数')
                    return
                  }
                  callback()
                },
                message: '${title}不能为空，且数量大于0' }],
            },
            {
              title: '售价',
              key: 'suggestedPrice',
              type: FormTypes.inputNumber,
              width:"100px",
              placeholder: '请输入${title}',
              defaultValue: 1,
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '原价',
              key: 'originalPrice',
              type: FormTypes.inputNumber,
              width:"100px",
              placeholder: '请输入${title}',
              // defaultValue: 1,
              validateRules: [{

                handler(type, value, row, column, callback, target){
                  console.log(value)
                  // console.log(row)

                  let  values  = target.getValuesSync({ validate:false,rowIds: [row.id] })
                  console.log(values)
                  if (Number(value)<=Number(values.values[0].suggestedPrice) ){
                    console.log(typeof  value)
                    console.log(typeof  Number(values.values[0].suggestedPrice))

                    callback(false,'原价必须大于售价！')
                    // callback()
                  }
                  /*let { values } = target.getValuesSync({ validate:false})
                  for (let resultElement of values) {
                    if (resultElement['yuanPrice']<=resultElement['suggestedPrice']){
                        callback(false,'原价必须大于售价！')
                        return
                    }
                  }*/
                  callback()
                },
                // message: '请选择${title}!'
              }],
            },
            {
              title: '售卖单位',
              key: 'unit',
              type: FormTypes.input,
              dictCode:"unit",
              width:"100px",
              // placeholder: '请选择${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '对应库存单位关系',
              key: 'weight',
              type: FormTypes.inputNumber,
              width:"140px",
              placeholder: '请输入${title}',
              defaultValue: 1,
              validateRules: [{
                required: true,
                handler(type, value, row, column, callback, target){
                  console.log(value)

                  if (!(/^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/.test(value))){
                    callback(false, '${title}数量必须大于0')
                    return
                  }
                  callback()
                },
                message: '${title}不能为空，且数量大于0' }],
            },
            {
              title: '库存单位',
              key: 'unitName',
              type: FormTypes.slot,
              slotName:'unitNameSlot',
              width:"100px",
              placeholder: '请输入${title}',
            },
          ]
        },
        url: {
          add: "/goods/goodsShelf/add",
          edit: "/goods/goodsShelf/edit",
          queryById: "/goods/goodsShelf/queryById",
          goodsShelfDetail: {
            list: '/goods/goodsShelf/queryGoodsShelfDetailByMainId'
          },
          queryByGoodsId:"goodsspecs/bizGoodsSpecs/queryByGoodsId/",
          queryMaxSort:"goods/goodsShelf/queryMaxSort"
        }
      }
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：false流程表单 true普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      numdisabled:{
        type: Boolean,
        default: false,
        required: false
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      numDisabled(){

        if(this.isFixNum){
          return true
        }else {
          return false
        }

      },

      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
      // console.log(this.isMiaosha)
    },
    methods: {
      /*售卖类型检测*/
      saleChange(e){
        //获取序号，秒杀类型不传值
        //dev 分支
        /*if(this.addMaxSort){
          if(e.target.value==0 || e.target.value==1){
              //请求接口
            this.confirmLoading = true;
            console.log(11111)
            //新增状态下 获取自动序号
            getAction(this.url.queryMaxSort+'/'+e.target.value).then((res)=>{
              console.log(res)
              if (res.success){
                let fieldval = pick(this.model,'goodsId','goodsName','sharePic','saleType','title','startTime','initSale','endTime','limitSale','keywords','newStatus','recommandStatus','sort','commission','integral')
                this.confirmLoading = false;
                fieldval.sort = res.result
                this.form.setFieldsValue(fieldval)
              }else {
                this.confirmLoading = false;
                this.$message.error(res.message)
              }
            })
          }else {
            let fieldval = pick(this.model,'goodsId','goodsName','sharePic','saleType','title','startTime','initSale','endTime','limitSale','keywords','newStatus','recommandStatus','sort','commission','integral')
            this.confirmLoading = false;
            fieldval.sort = 1
            this.form.setFieldsValue(fieldval)
          }
        }*/


        console.log(e.target.value)
        if (e.target.value == 2){
          this.isMiaosha = true
          // this.form.setFieldsValue('startTime','')
          this.form.resetFields('startTime')
          this.form.resetFields('endTime')
          this.$refs.goodsShelfDetail.initialize()
        }else {
          this.isMiaosha = false
        }
      },
      /*子表新增*/
      add1(){
        let { error, values } = this.$refs.goodsShelfDetail.getValuesSync({validate:true})
        console.log(values)
        /*先判断是不是秒杀商品  是的话 只准新增一条数据*/
        if (this.isMiaosha && values.length>=1){
          this.$message.error('秒杀商品只允许添加一条明细')
        }else {
          this.$refs.goodsShelfDetail.handleClickAdd()
        }


      },
      /*字表删除*/
      del1(){
        this.$refs.goodsShelfDetail.handleConfirmDelete()
      },
      //规格下拉选择改变事件
      xialaxuanze(props,e){
        console.log(e)
        console.log(props)
        let { rowId, target } = props
        target.setValues([{
          rowKey: rowId,
          values: { // 在这里 values 中的 name 是你 columns 中配置的 key
            'goodsSpecsId': e,
          }
        }])
      },
      kkk(props,e){
        console.log(e)
        let { rowId, target } = props
        target.setValues([{
          rowKey: rowId,
          values: { // 在这里 values 中的 name 是你 columns 中配置的 key
            'quantity': e,
          }
        }])
      },
      //规格下拉弹窗
      // handleOk(e) {
      //   this.visible1 = false;
        /*this.confirmLoading = true;
        setTimeout(() => {
          this.visible1 = false;
          this.confirmLoading = false;
        }, 2000);*/
      // },
      handleCancel(e) {
        this.visible1 = false;
      },
      addBefore(){
        this.form.resetFields()
        this.goodsShelfDetailTable.dataSource=[]
      },
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {

        let fieldval = pick(this.model,'goodsId','goodsName','sharePic','saleType','title','startTime','initSale','endTime','limitSale','keywords','newStatus','recommandStatus','sort','commission','integral')
        /*新增上架时候获取序列号 默认售卖类型是普通  值为0*/
        //dev 分支1
        /*if (this.addMaxSort){
          this.confirmLoading = true;
          console.log(11111)
          //新增状态下 获取自动序号
          getAction(this.url.queryMaxSort+'/0').then((res)=>{
            console.log(res)
            if (res.success){
              this.confirmLoading = false;
              fieldval.sort = res.result
              this.form.setFieldsValue(fieldval)
            }else {
              this.confirmLoading = false;
              this.$message.error(res.message)
            }
          })
        }*/
        this.$nextTick(() => {
          // console.log(fieldval)
          this.form.setFieldsValue(fieldval)
        })

        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          getAction(this.url.goodsShelfDetail.list,params).then((res)=>{
            let {result} =res
            this.goodsShelfDetailTable.dataSource= result
            this.goodsShelfDetailTable.unitName=result[0].unitName
          })
          // this.requestSubTableData(this.url.goodsShelfDetail.list, params, this.goodsShelfDetailTable)

          let unitName= this.goodsShelfDetailTable.dataSource
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          goodsShelfDetailList: allValues.tablesValue[0].values,
        }
      },
      handleOk() {
        let unitName=this.goodsShelfDetailTable.unitName
        this.getAllTable().then(tables => {
          return validateFormAndTables(this.form, tables)
        }).then(allValues => {
          if (typeof this.classifyIntoFormData !== 'function') {
            throw this.throwNotFunction('classifyIntoFormData')
          }
          let formData = this.classifyIntoFormData(allValues)
          if(formData.goodsShelfDetailList.length==0){
            this.$message.warning('请添加商品上架商品明细')
            return false
          }
          // if(formData.goodsShelfDetailList[0].unitName==''||formData.goodsShelfDetailList.unitName==null||formData.goodsShelfDetailList.unitName==undefined){
          //   this.$message.warning('库存单位未设置不能提交')
          //   return false
          // }

          for(let i in formData.goodsShelfDetailList ){
            formData.goodsShelfDetailList[i].unitName= unitName
              if(formData.goodsShelfDetailList[i].unitName==''){
                this.$message.warning('库存单位未设置不能提交')
                return false
              }
          }
          // 发起请求
          console.log('formData',formData)
          // debugger
          return this.request(formData)
        }).catch(e => {
          if (e.error === VALIDATE_NO_PASSED) {
            this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
          } else {
            console.error(e)
          }
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          })
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },
     popupCallback(row){
       this.form.setFieldsValue(pick(row,'goodsId','goodsName','sharePic','unitName','title','saleType','startTime','initSale','limitSale','endTime','keywords','newStatus','recommandStatus','sort','commission','integral'))
       // this.unitName=this.form.getFieldValue('unitName')
       this.goodsShelfDetailTable.unitName=row.unitName
       // this.unitName=row.unitName
       /*重置子表*/
       this.$refs.goodsShelfDetail.initialize()


       this.optionsArray= []
       let ccc = this.form.getFieldValue('goodsId')
       getAction(this.url.queryByGoodsId+ccc).then((res)=>{
         if (res.success){
           if (res.result){
             for (let res of res.result) {
               let obj = {}
               let obj1 = {}
               obj.id = res.id
               obj.stock = res.stock
               obj.specsValues = []
               obj1.stock = res.stock
               obj1.specsValues = []

               obj1.id = res.id
               for (let argument of res.specsValues) {
                 if (argument.attributeName !== 'sortNum' && argument.attributeName !== 'image'){
                   obj1.specsValues.push(argument)
                   obj.specsValues.push(argument)
                 }
               }
               this.goodsIds.push(obj)
               this.optionsArray.push(obj1)
             }

             // this.goodsShelfDetailTable.columns[0].options = this.optionsArray
             console.log('this.optionsArray',this.optionsArray)
             // this.tableShow = true
             // this.$refs.goodsShelfDetail.initialize()
           }else {
             this.$message.error('该商品没有规格！')
           }
         }else {
           this.$message.error(res.message)
         }
       })



     },


      //下拉规格内置方法
      /*ceshi(d){
        let { rowId, target } = d
        console.log()
        target.setValues([{
          rowKey: rowId,
          values: { // 在这里 values 中的 name 是你 columns 中配置的 key
            'goodsSpecsId': '2222222222222',
          }
        }])
        this.visible1 = true
      },*/



      //回显获取下拉菜单渲染
      selectMenuCreat(id){
        this.optionsArray= []
        // let ccc = this.form.getFieldValue('goodsId')
        getAction(this.url.queryByGoodsId+id).then((res)=>{
          // console.log(res)
          if (res.success){
            if (res.result){
              for (let res of res.result) {
                let obj = {}
                let obj1 = {}
                obj.id = res.id
                obj.stock = res.stock
                obj.specsValues = []
                obj1.stock = res.stock
                obj1.specsValues = []

                obj1.id = res.id
                for (let argument of res.specsValues) {
                  if (argument.attributeName !== 'sortNum' && argument.attributeName !== 'image'){
                    obj1.specsValues.push(argument)
                    obj.specsValues.push(argument)
                  }
                }
                this.goodsIds.push(obj)
                this.optionsArray.push(obj1)
              }

              // this.goodsShelfDetailTable.columns[0].options = this.optionsArray
              // console.log('this.optionsArray',this.optionsArray)
              // this.tableShow = true
              // this.$refs.goodsShelfDetail.initialize()
            }else {
              this.$message.error('该商品没有规格！')
            }
          }else {
            this.$message.error(res.message)
          }
        })
      }

    }
  }
</script>

<style scoped>
</style>